/**
* @file qoregister.cpp
* @describe Qo注册界面
* @author gaoyuelong
* @date 2022/05/04
*/

#include "qoregister.h"
#include "ui_qoregister.h"
#include "common.h"
#include "network/qotcp.h"
#include "qousercontrol.h"
#include <QMessageBox>
#include <QClipboard>

QoRegister::QoRegister(QDialog *parent) :
    QDialog(parent),
    ui(new Ui::QoRegister)
{
    ui->setupUi(this);
    ui->widget->hide();

    m_pQoControl = new QoControl();
    qDebug() << "connect";
    connect(m_pQoControl, SIGNAL(signalReg(const QString &)), this, SLOT(slotReg(const QString &)));
}

QoRegister::~QoRegister()
{
    delete m_pQoControl;
    m_pQoControl = nullptr;
    delete ui;
}

void QoRegister::on_btnRegister_clicked()
{
    //判断密码和确认密码是否一致
    if (ui->lineeditPwd->text() != ui->lineeditSurePwd->text()) {
        QMessageBox::information(this, "tips", QString::fromUtf8("请保证两次输入的密码一致！"));
        return;
    }

    m_pQoControl->reg(ui->lineeditNickName->text(), ui->lineeditPwd->text());
}
#include <QDebug>
void QoRegister::slotReg(const QString &strAccount)
{
    qDebug() << "slotReg";
    qDebug() << strAccount;
    if (strAccount != "") {
        int ret;
        if ((ret = QMessageBox::information(this, "tips", QStringLiteral("%1 Registered successfully!\nClick OK to copy the account to the clipboard").arg(strAccount), QMessageBox::Ok))
                == QMessageBox::Ok) {
            QClipboard *clipboard = QApplication::clipboard();   //获取系统剪贴板指针
            QString originalText = clipboard->text();         //获取剪贴板上文本信息
            clipboard->setText(strAccount);
            close();
        }
    } else {
        QMessageBox::information(this, "tips", QString("register failed"));
        return;
    }
}
